import { Controller, Get, Post, Body, Query, Req, HttpException, HttpStatus } from '@nestjs/common';
import { StageService } from './stage.service';
import { CreateStageDto } from './dto/create-stage.dto';
import { ApiBearerAuth, ApiQuery } from '@nestjs/swagger';
import { Auth } from 'src/common/decorators/auth.decorator';
import { RequirePermission } from 'src/common/decorators/permission.decorator';
import logger from 'src/common/utils/log';
import { lastValueFrom } from 'rxjs';
import { HttpService } from '@nestjs/axios';

@Auth()
@ApiBearerAuth()
@Controller('stage')
export class StageController {
  constructor(
    private readonly stageService: StageService,
    private readonly httpService: HttpService,
  ) {}

  @RequirePermission('1003002')
  @Post()
  async create(@Req() req, @Body() createStageDto: CreateStageDto) {
    return '该接口废弃，请更换为 /stage/stageCreate';
  }

  // @Get(':id')
  // async findOne(@Param('id') id: string) {
  //   return this.stageService.findOne(+id);
  // }
  @RequirePermission('1003001')
  @Get('getDetail')
  async getDetail(@Query('id') id: string) {
    return this.stageService.getDetail(+id);
  }

  @Get('getStageMatches')
  async getStageMatches(@Query('stageId') id: string) {
    return '该接口废弃，请更换为 common/stage-matches/getStageMatches';
  }
  @RequirePermission('1003002')
  @Post('copyStage')
  @ApiQuery({
    name: 'stageId',
    type: Number,
    description: 'copy 的stage Id',
    required: true,
  })
  @ApiQuery({
    name: 'isCopySchedule',
    type: Boolean,
    description: '是否copy 赛程',
    required: false,
    default: true,
  })
  @ApiQuery({
    name: 'isCopyE2P',
    type: Boolean,
    description: '是否copy 选手落位',
    required: false,
    default: true,
  })
  async copyStage(
    @Req() request,
    @Query('stageId') stageId: number,
    @Query('isCopySchedule') isCopySchedule: boolean = true,
    @Query('isCopyE2P') isCopyE2P: boolean = true,
  ) {
    return await this.stageService.copyStage(
      stageId,
      isCopySchedule,
      isCopyE2P,
      request.user,
    );
  }

  // @RequirePermission('1003002')
  // @ApiOperation({ summary: '复制阶段数据' })
  // @ApiResponse({ status: 200, description: '阶段数据复制成功' })
  // @ApiBody({ type: CopyStageDto, description: '复制阶段所需的参数' })
  // @Post('copyStage')
  // async copyStage(@Body() copyStageDto: CopyStageDto) {
  //   return this.stageService.copyStage(copyStageDto);
  // }
  // @RequirePermission('1003003')
  // @Patch(':id')
  // async update(
  //   @Param('id') id: string,
  //   @Body() updateStageDto: UpdateStageDto,
  // ) {
  //   return await this.stageService.update(+id, updateStageDto);
  // }

  // @Delete(':id')
  // async remove(@Param('id') id: string) {
  //   return await this.stageService.remove(+id);
  // }
}
